package com.apetrenko.avaya.callstore.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

public class CallStore implements EntryPoint, ValueChangeHandler<String> {

	private static CallStore cSingleton;

	private static final int LOGIN_PANE = 0;
	private static final int MGR_PANE = 1;
	private static final int SETTINGS_PANE = 2;

	//private DockPanel iOuter = new DockPanel();

	private StartPane iStartPane = new StartPane();
	private ManagerPane iMgrPane = new ManagerPane();
	private SettingsPane iSettingsPane = new SettingsPane();

	private DeckPanel iDeck = new DeckPanel();

	

	public static CallStore get() {
		return cSingleton;
	}

	public void onModuleLoad() {
		cSingleton = this;
		setupHistory();
		setupPanes();
		//setPane(LOGIN_PANE);
		setPane(MGR_PANE);
	}

	private void setPane(int aPane) {
		iDeck.showWidget(aPane);
	}

	private void setupPanes() {
		iDeck.insert(iStartPane, LOGIN_PANE);
		iDeck.insert(iMgrPane, MGR_PANE);
		iDeck.insert(iSettingsPane, SETTINGS_PANE);

		iDeck.setWidth("100%");
		Window.enableScrolling(false);
		Window.setMargin("0px");
		RootPanel.get().add(iDeck);
	}
	
	private void setupHistory() {
		History.addValueChangeHandler(this);
	}

	@Override
	public void onValueChange(ValueChangeEvent<String> aEvent) {
		// TODO Auto-generated method stub
		
	}
	
	public void startSession(long aId) {
		setPane(MGR_PANE);
	}
	
	public void clearCenterPanel() {
		iMgrPane.clearCenterPanel();
	}

	public void setCenterPanel(Widget aWidget) {
		iMgrPane.setCenterPanel(aWidget);
	}
}
